<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>csv上傳</title>
</head>
<body>
<?php
session_start();
$upload_dir = "upload/";
$total_uploads = 1;
$albumName = $_POST['uploadAlbumName'];
$size_bytes =1024 * 1024;//1mb
$limitedext = array(".gif",".jpg",".jpeg",".png");//限制上傳副檔名
echo "<h3>您選擇上傳到->".$_POST['uploadAlbumName']."</h3>";// 
$new_file = $_FILES['pic0'];
//var_dump($new_file);
$file_name=$new_file['name'];//取得上傳檔名
//echo $file_name."<br />";
$file_size = $new_file['size'];//取得檔案大小
//echo ($file_size/1024)."<br>";
$file_tmp = $new_file['tmp_name'];//取得暫存區檔名
//echo $file_tmp."<br>";
$file_size = $new_file['size'];
if(!is_uploaded_file($file_tmp))
{
   echo "沒有上傳任何東西喔!!!<br />";
}
else
{
   $ext = strrchr($file_name,".");//取出副檔名
   echo $ext."<br>";
   if(!in_array(strtolower($ext),$limitedext))
   {
      echo "上傳檔案的副檔名有錯喔!!只允許(GIF&JPEG)<br />";
   }
   else
   {      
      if($file_size>$size_bytes)
      {
         echo "檔案太大，請小於".($size_bytes/1024)."KB<br />";
      }
      else
      {
         if (move_uploaded_file($file_tmp,$upload_dir."/$albumName/".$file_name))
         {
		   	echo "($file_name) 上傳成功！<br />";
		   	$oriPic = $upload_dir."/$albumName/".$file_name;
		   	/**執行縮圖處理
		   	 * 
		   	 */		   	
		   	exec("convert  -geometry 100 $oriPic $upload_dir/$albumName/small/"."small_$file_name");
		   /**處理存入圖片名稱(picName)、路徑(path)、擁有者(owner)、時間(date)
		    * 
		    */
		   	$album = new Album();
		   	$owner = $_SESSION['user'];
		   	$date = date("Y:m:d H:i:s");
		   	$path = $upload_dir."$albumName/";	
		   	$picName = $file_name;
		 	$album->setOwner($owner);
		 	$album->setDate($date);
		 	$album->setAlbumname($albumName);
		 	$album->setPath($path);
		 	$album->setPicname($picName);
		 	$album->save();		 	
         }
         else
         {
		   echo "無法上傳。<br />";
		 }
      }
   }
}
?>
</body>
</html>